﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Tali.Entity;

namespace Tali.Models
{
    public class User
    {
        [Required]
        [Display(Name = "User Id")]
        public string tlUserId { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string tlPassword { get; set; }

        [Display(Name = "Remember on this computer")]
        public bool RememberMe { get; set; }

        /// <summary>
        /// Checks if user with given password exists in the database
        /// </summary>
        /// <param name="_username">User name</param>
        /// <param name="_password">User password</param>
        /// <returns>True if user exist and password is correct</returns>
        public bool IsValid(string _username, string _password)
        {
            var Entityes = new Tali2014Entities();
            var userlogon = Entityes.TL_USERS.Where(u => u.tlUserId == _username && u.tlPassword == _password).FirstOrDefault();
            if (userlogon != null)
                return true;
            else
                return false;
        }
    }
}